Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@poppinss/response

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@poppinss/response

Wrapper over Node.js res, making it easier to send HTTP responses

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Response

circleci-image npm-image license-image

Wrapper over NodeJs res object to simplify the process of sending HTTP response.

Features

  1. Simple to use API for making HTTP response.
  2. Properly closes the streams pipe to the response object.
  3. Support for lazily sending the response. Helpful when you want to mutate the response inside a downstream middleware.
  4. Etag generation.
  5. In built support for sending plain and signed cookies.

Table of contents

Usage

Install the package from npm as follows:

npm i @poppinss/response

# yarn
yarn add @poppinss/response

and then use it as follows

import { Response, ResponseConfigContract } from '@poppinss/response'
import { createServer } from 'http'

const config: ResponseConfigContract = {
  etag: false,
  jsonpCallbackName: 'callback',
  secret: 'optional-secret-to-sign-cookies',
  cookie: {},
}

createServer((req, res) => {
  const response = new Response(req, res, config)

  response.send({ hello: 'world' }) // objects
  response.send(Buffer.from('hello world')) // buffer
  response.send(true) // boolean
  response.send(10) // numbers
  response.send('<p> Hello world </p>') // html

  response.pipe(fs.createReadStream('profile.jpg')) // streams
  response.download('path/to/file.jpg') // stream files
  response.attachment('path/to/file.jpg') // set Content-Disposition header

  response.cookie('session-id', '1') // set signed cookie
})

Config

{
"etag": false

Whether or not to generate etag for all responses. Etag helps the browser for re-using the cache response when etags are same. Default value is false

"jsonpCallbackName": "callback"

The callback name for the JSONP response. In case of dynamic callback names, you can passing it inline when calling response.jsonp() method.

"secret"

Optional Define a secret to sign cookies.

"cookie"

Partial Config to generate the cookie header. Make sure to check cookie package docs for list of available options.

}

API

Following are the autogenerated files via Typedoc

Maintainers

Harminder virk

Keywords

FAQs

Package last updated on 30 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc